Skip to content

Migrate to pytest and expand test coverage#20

Merged
marcarl merged 7 commits into
mainfrom
feature/pytest-migration
Jan 3, 2026
Merged

Migrate to pytest and expand test coverage#20
marcarl merged 7 commits into
mainfrom
feature/pytest-migration

Conversation

@marcarl
Copy link
Copy Markdown
Collaborator

@marcarl marcarl commented Jan 2, 2026

Sammanfattning

Migrera hela testsviten från fristående Python-skript till pytest med moderna testmetoder:

  • Ersätt print-statements med riktiga assertions
  • Mock:a alla externa API-anrop till Riksdagen
  • Lägg till pytest-konfiguration och CI/CD

Ändringar

Nya filer

  • pyproject.toml - pytest-konfiguration med markers, coverage-inställningar
  • test/conftest.py - Delade fixtures och API-mocks
  • .github/workflows/test-workflow.yml - GitHub Actions för automatisk testning

Migrerade testfiler

  • test_linking.py - Parametriserade tester för länkgenerering (9 tester)
  • test_title_temporal.py - Unit-tester för temporal titellogik (7 tester)
  • test_integrated_title_temporal.py - Integrationstester med tmp_path (5 tester)
  • test_predocs.py - API-tester med mocking (19 tester)

Testresultat

Alla 40 tester passerar (100% framgång)

pytest -v
# 40 passed in 1.33s

Test coverage

  • 13% total coverage (bas för förbättring)
  • Alla API-anrop mockade med requests-mock
  • Inga riktiga nätverksanrop i testerna

Test markers

pytest -m unit         # Snabba unit-tester
pytest -m integration  # Integrationstester  
pytest -m api          # API-tester (mockade)
pytest -m "not slow"   # Hoppa över långsamma tester

CI/CD

GitHub Actions workflow kör automatiskt vid:

  • Push till main/develop
  • Pull requests till main
  • Manuell trigger

Tester körs på Python 3.10, 3.11, 3.12 och genererar coverage-rapporter.

Förbättringar

Tidigare:

  • ❌ Print-statements för verifiering
  • ❌ Manuell körning med python test/test_*.py
  • ❌ Riktiga API-anrop till Riksdagen
  • ❌ Ingen CI/CD
  • ❌ Ingen coverage-tracking

Nu:

  • ✅ Riktiga assertions med pytest
  • ✅ Automatisk testdiscovery
  • ✅ Mockade API-anrop
  • ✅ GitHub Actions CI/CD
  • ✅ Coverage-rapporter

🤖 Generated with Claude Code

marcarl and others added 7 commits January 2, 2026 23:01
- Ersätt print-baserade tester med riktiga assertions
- Använd parametriserade tester för bättre täckning
- Mock:a alla externa API-anrop med requests-mock
- Lägg till pytest-konfiguration i pyproject.toml
- Skapa GitHub Actions workflow för CI/CD
- Alla 40 tester passerar (100% framgång)

Tester körs nu automatiskt vid push/PR och använder:
- Test markers (unit, integration, api, slow)
- Coverage tracking (13% för närvarande)
- Mockade Riksdagen API-svar
- pytest fixtures för delad testdata

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- .coverage (coverage data file)
- htmlcov/ (HTML coverage report)
- .pytest_cache/ (pytest cache)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…oming changes

- Implemented comprehensive unit tests for the `load_json_file`, `has_expiring_datetime`, `find_expiring_files`, `print_results`, and `save_results_to_file` functions.
- Added integration tests to validate the complete workflow of finding expiring documents.
- Created unit tests for the `identify_upcoming_changes`, `save_upcoming_file`, `get_doc_ids_for_date`, `get_earliest_pending_date`, and `extract_doc_id_from_filename` functions.
- Included edge case tests to ensure robustness against various scenarios, including invalid date formats and handling of special characters.
…ameterized inputs for better coverage and maintainability
@marcarl marcarl changed the title Migrera testerna till pytest med moderna testmetoder Migrate to pytest and expand test coverage from 13% to 35% Jan 3, 2026
@marcarl marcarl changed the title Migrate to pytest and expand test coverage from 13% to 35% Migrate to pytest and expand test coverage Jan 3, 2026
@marcarl marcarl merged commit ad04426 into main Jan 3, 2026
5 checks passed
@marcarl marcarl deleted the feature/pytest-migration branch January 3, 2026 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant